package com.example.worldcupsever;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.os.Bundle;
import android.widget.RadioGroup;

import com.example.worldcupsever.fragment.GerenFragment;
import com.example.worldcupsever.fragment.LianxiFragment;
import com.example.worldcupsever.fragment.ShouFragment;
import com.example.worldcupsever.fragment.ZixunFragment;

public class HomeActivity extends AppCompatActivity {
    RadioGroup mRGNavi;
    private FragmentManager FragmentManger;
    private FragmentManager supportFragmentManger;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_home);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.fl_container, new ShouFragment())
                .commit();
            
            initView();
            initEvent();
        }

    private void initEvent() {
            mRGNavi.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    switch (checkedId){
                        case R.id.rb_shouye:
                            //动态替换fragment
                            supportFragmentManger = getSupportFragmentManager();
                            supportFragmentManger.beginTransaction()
                                    .replace(R.id.fl_container, new ShouFragment())
                                    .commit();

                        break;
                        case  R.id.rb_zixun:
                            FragmentManger = getSupportFragmentManager();
                            FragmentManger.beginTransaction()
                                    .replace(R.id.fl_container, new ZixunFragment())
                                    .commit();

                            break;
                        case  R.id.rb_lianxi:
                            FragmentManger = getSupportFragmentManager();
                            FragmentManger.beginTransaction()
                                    .replace(R.id.fl_container, new LianxiFragment())
                                    .commit();

                            break;
                        case R.id.rb_geren:
                            FragmentManger = getSupportFragmentManager();
                            FragmentManger.beginTransaction()
                                    .replace(R.id.fl_container, new GerenFragment())
                                    .commit();

                            break;
                    }

                }
            });
    }

    private void initView() {
            mRGNavi = findViewById(R.id.rg_navi);
    }

}
